package ExecuteEngine;

public class CrossProduct implements Operation{
	public Operation Op1;
	public Operation Op2;
	public Tuple t1;
	public Tuple t2;
	public Tuple t;
	public int mark = 0;
	
	public CrossProduct(Operation o1, Operation o2){
		this.Op1 = o1;
		this.Op2 = o2;
	}
	
	public void Open(){
		Op1.Open();
		Op2.Open();
	}
	
	public boolean hasNext(){
		if(Op2.hasNext() == false){
			if(Op1.hasNext() == false)
				return false;
		}
		else
		{
			Op2.Close();
			Op2.Open();
			mark = 1;
		}
		
		return true;
	}
	
	public Tuple GetNext()
	{
		t2 = Op2.GetNext();
		
		if(mark == 1){
			t1 = Op1.GetNext();
			mark = 0;
		}
		
		t = new Tuple(t1);
		t.addTuple(t2);
		
		return t;
	}
	
	public void Close(){
		Op1.Close();
		Op2.Close();
	}
}
